cmake_minimum_required(VERSION 3.28)
project(BBDemo)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "-g")

include_directories(src common)

link_directories(/home/guo/work/cpp/BBDemo/cmake-build-debug)

#对象库
aux_source_directory(common common_files)
add_library(common_obj OBJECT ${common_files}
        common/protocol.h
        common/struct.h)

aux_source_directory(src blackboard_files)
add_library(blackboard_obj OBJECT ${blackboard_files})

##bbserver
#add_executable(bbserver
#        test/bbserver_test.cpp
#        src/Blackboard.cpp
#        src/BBServer.cpp
#        src/BBServer.h)
#target_link_libraries(bbserver common_obj)
#
##bbclient
#add_executable(bbclient
#        test/bbclient_test.cpp
#        src/Blackboard.cpp
#        src/BBClient.cpp
#        src/BBClient.h)
#target_link_libraries(bbclient common_obj)

#主程序
add_executable(bbdemo main.cpp)
add_dependencies(bbdemo blackboard_obj)
target_link_libraries(bbdemo blackboard_obj common_obj)

#单元测试
set(test_dir ${CMAKE_CURRENT_SOURCE_DIR}/test)
file(GLOB_RECURSE test_files RELATIVE ${test_dir} ${test_dir}/*.cpp)
foreach (file ${test_files})
    if(NOT IS_DIRECTORY ${file})
        string(REGEX MATCH "[^.]+" filename "${file}")
        add_executable(${filename} ${test_dir}/${file})
        target_link_libraries(${filename} blackboard_obj common_obj)
    endif ()
endforeach ()

